﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InformationSystem.BLL.Core.Service;
using InformationSystem.BLL.Core.Model;
using InformationSystem.Utility;
using Ext.Net;

namespace InformationSystem.WebSite.Module.AuthorityMgr
{
    public partial class SysUserMgr : System.Web.UI.Page
    {
        public IUserService UserService { get; set; }
        public ICollegeService CollegeService { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                //读取用户信息
                List<LoginUser> userlist = UserService.GetSysUser();
                this.userListStore.DataSource = userlist;
                this.userListStore.DataBind();

                //读取学年度信息
                cmbGrade.Items.Add(new Ext.Net.ListItem("0"));
                foreach (var item in GradeUtility.GetRightGradeInfo())
                {
                    cmbGrade.Items.Add(new Ext.Net.ListItem(item.ToString()));
                }
                //读取学院信息
                cmbcollege.Items.Add(new Ext.Net.ListItem("--"));
                foreach (var item in CollegeService.GetAllCollegeInfo())
                {
                    cmbcollege.Items.Add(new Ext.Net.ListItem(item.CollegeName.ToString()));
                }
            }

        }

        protected void AfterStoreChanged(object sender, AfterStoreChangedEventArgs e)
        {
            List<LoginUser> userlist = UserService.GetSysUser();
            this.userListStore.DataSource = userlist;
            this.userListStore.DataBind();
            this.userListStore.RefreshAfterSaving = RefreshAfterSavingMode.Always;
        }

        protected void BeforeRecordInserted(object sender, BeforeRecordInsertedEventArgs e)
        {
            LoginUser user = e.Object<LoginUser>();
            if (user.UserID == string.Empty || user.UserName == string.Empty) return;
            bool result=  UserService.CreateSysUserInfo(user);
        }

        protected void BeforeRecordDeleted(object sender, BeforeRecordDeletedEventArgs e)
        {
            LoginUser user = e.Object<LoginUser>();
            if (user.UserID == string.Empty || user.UserName == string.Empty) return;
            this.UserService.DeleteSysUserByID(user.UserID);
        }

        protected void BeforeRecordUpdated(object sender, BeforeRecordUpdatedEventArgs e)
        {
            LoginUser user = e.Object<LoginUser>();
            if (user.UserID == string.Empty || user.UserName == string.Empty) return;
            UserService.UpdateSysUserInfo(user);
        }





    }
}